Objective
Know how to install, configure and maintain an HTTP server on Unix.
Hardware & requirements
A PC running CentOS / Rocky Linux, the Apache HTTP server software, a web browser.
01Installation or update
Apache is highly modular, which makes it easy to add extensions to the server (PHP module, SSL module…). Install it with all necessary dependencies — package httpd:
In the list of files of the httpd package, find:
- The path to the
httpdexecutable. - The path to the configuration file
httpd.conf.
rpm -qa lists all installed packages; rpm -ql httpd lists the files of the package.02Launch
- Start the
httpdservice with theservicecommand, as usual. - Which URL does your web server respond to?
- Test access to your server with a browser.
- Check that the
httpdservice is running by noting its PID.
03Configuration
As root, edit /etc/httpd/conf/httpd.conf — make a backup first. Lines starting with # are comments.
- Give your server a name by setting the
ServerNamevariable. What is this name used for? - What would you need to do to reach your server "www.myfirstwebserver.fr" at http://www.myfirstwebserver.fr/?
- The
Includedirective includes other configuration files: which files are included? - The
DocumentRootvariable holds the directory where the server's documents are placed.- Note its value.
- Create a sub-folder with your name and change the path so it becomes the new root of your site. Also change the path in the matching
<Directory …>section. - Put a custom
index.htmlpage in the new root directory. - Restart Apache with the
servicecommand. - Test access at
http://localhost.
- What is the role of the
DirectoryIndexvariable? What is its value? - Using the official documentation, what is the role of
AccessFileName? What is its default value? - Using the official documentation, what are
Aliasdirectives used for?
UserDir module
The UserDir module lets users of the host machine create a directory whose documents are published on the web. Configuration file: /etc/httpd/conf.d/userdir.conf.
- Change the value of the
UserDirvariable in the configuration file. - Restart the service with
serviceto apply it. - Create an
index.htmlpage in the web directory defined byUserDirfor the Unix user accounttoto. - Run
chmod 755 /path/to/home/tototo change permissions (the Apache user needs access). - Restart Apache.
- Run
setsebool -P httpd_enable_homedirs true(SELinux). - Test access at
http://localhost/~toto(note the tilde).
Logs
- Look at
/etc/httpd/logs/access_log(withtail -f access_log) and/etc/httpd/logs/error_log. - What information do they contain?
- How can these files help you debug a site?
04Security
We want to protect access to a directory called secret in /var/www/html/yourname/secret. Add a section at the end of httpd.conf with these directives:
| Directive | Role |
|---|---|
Options Indexes | Lists the directory content if there is no index.html. |
AllowOverride None | Protection can only be changed from the main configuration file. |
AuthType Basic | Type of authentication. |
AuthName | Text shown in the login dialog box. |
Require user | Restricts access to specific users. |
User and group creation
- Create the password file:
htpasswd -c /etc/httpd/conf/passwd [username](drop-cfor the next users). - Create the group file
/etc/httpd/conf/groupin the formatgroupname: user1 user2 user3. - Edit
httpd.confto test password access for users, then for a group (Require group).
05Links
Complete Apache documentation: httpd.apache.org/docs/2.4